<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="类型" prop="categoryId" >
          <treeselect v-model="queryParams.categoryId"  style="width: 13.25rem;"    :options="materialcategoryOptions"  @keyup.enter.native="handleQuery" :show-count="true" placeholder="请选择类别" />
      <!--  <el-input v-model="queryParams.categoryId" placeholder="请输入产品类型id" clearable size="small"
          @keyup.enter.native="handleQuery" /> -->
      </el-form-item>
      <el-form-item label="条码" prop="barCode">
        <el-input v-model="queryParams.barCode" placeholder="请输入条码" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入名称/首字母" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

 <el-form-item label="规格" prop="standard">
        <el-input v-model="queryParams.standard" placeholder="请输入规格" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="型号" prop="model">
        <el-input v-model="queryParams.model" placeholder="请输入型号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['material:material:add']">新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['material:material:edit']">修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['material:material:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['material:material:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['material:material:export']">导出</el-button>
      </el-col>
       <el-col :span="1.5">
      <el-dropdown  @command="handlePlCommand">
        <el-button  size="mini">
          批量操作<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu  slot="dropdown">
          <el-dropdown-item icon="el-icon-circle-check" command="1">启用</el-dropdown-item>
          <el-dropdown-item icon="el-icon-circle-close" command="2">禁用</el-dropdown-item>
        <el-dropdown-item icon="el-icon-finished" command="3">修正库存</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
       </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" max-height="620px" :data="materialList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" v-if="false" align="center" prop="id" />
      <el-table-column label="条码" align="center" prop="barCode" />
       <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="规格" align="center" prop="standard" />
      <el-table-column label="型号" align="center" prop="model" />
      <el-table-column label="颜色" align="center" prop="color" />
      <el-table-column label="类别" align="center" prop="categoryName" />
      <el-table-column label="扩展信息" align="center" prop="mfrs" >
        <template slot-scope="scope">
        <span v-if="scope.row.mfrs!=null">({{scope.row.mfrs}})</span>
        <span v-if="scope.row.otherField1!=null">({{scope.row.otherField1}})</span>
        <span v-if="scope.row.otherField2!=null">({{scope.row.otherField2}})</span>
        <span v-if="scope.row.otherField3!=null">({{scope.row.otherField3}})</span>
          </template>
        </el-table-column>
      <el-table-column label="单位" align="center" prop="unit" :formatter="getUnitName" />
      <el-table-column label="保质期" align="center" prop="expiryNum" />
      <el-table-column label="库存" align="center" prop="currentNumber" />
      <el-table-column label="采购价" align="center" prop="purchaseDecimal" />
      <el-table-column label="零售价" align="center" prop="commodityDecimal" />
      <el-table-column label="销售价" align="center" prop="wholesaleDecimal" />
      <el-table-column label="最低售价" align="center" prop="lowDecimal" />
      <el-table-column label="状态" align="center" prop="enabled" >
        <template slot-scope="scope">
           <el-tag v-if="scope.row.enabled==0" type="danger">禁用</el-tag>
           <el-tag v-if="scope.row.enabled==1" >启用</el-tag>
          </template>
        </el-table-column>
      <el-table-column label="序列号" align="center"  prop="enableSerialNumber" >
        <template slot-scope="scope">
           <el-tag v-if="scope.row.enableSerialNumber==0" type="danger">无</el-tag>
           <el-tag v-if="scope.row.enableSerialNumber==1" >有</el-tag>
          </template>
        </el-table-column>
      <el-table-column label="批号" align="center" prop="enableBatchNumber" >
        <template slot-scope="scope">
           <el-tag v-if="scope.row.enableBatchNumber==0" type="danger">无</el-tag>
           <el-tag v-if="scope.row.enableBatchNumber==1" >有</el-tag>
          </template>
        </el-table-column>
      <!--
<el-table-column label="制造商" align="center" prop="mfrs" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="图片名称" align="center" prop="imgName" />
      <el-table-column label="计量单位Id" align="center" prop="unitId" />

      <el-table-column label="基础重量(kg)" align="center" prop="weight" />

      <el-table-column label="自定义1" align="center" prop="otherField1" />
      <el-table-column label="自定义2" align="center" prop="otherField2" />
      <el-table-column label="自定义3" align="center" prop="otherField3" />

      <el-table-column label="租户id" align="center" prop="tenantId" />
      <el-table-column label="删除标记，0未删除，1删除" align="center" prop="deleteFlag" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['material:material:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['material:material:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改产品对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1300px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-tabs v-model="activeName" @tab-click="handleTabClick">
          <el-tab-pane label="基本信息" name="first">
            <el-row>
              <el-col :span="6">
                <el-form-item label="名称" prop="name">
                  <el-input v-model="form.name" placeholder="请输入名称" autofocus="true" @change="checkName" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="首字母" prop="name">
                  <el-input v-model="form.chineseChar" placeholder="请输入首字母" autofocus="true" @change="checkName" />
                </el-form-item>
              </el-col>

              <el-col :span="6">
                <el-form-item label="规格" prop="standard">
                  <el-input v-model="form.standard" placeholder="请输入规格" />
                </el-form-item>
              </el-col>

  <el-col :span="6" >
                              <el-form-item label="单位" prop="unit">
                                <el-row >
                                  <el-col :span="14" >
                                <el-input v-model="form.unit" placeholder="请输入单位" @change="unitChange" v-if="!isMangUnit" />
                                <el-select v-model="form.unitId"  v-if="isMangUnit" @change="mangUnitChange"
                                                   >
                                                     <el-option v-for="item in allUnitList" :key="item.id" :label="item.name"
                                                       :value="item.id">
                                                     </el-option>
                                                   </el-select>
                                </el-col>


                                <el-col :span="8" >
                                  <el-checkbox style="margin-left: 0.655rem;" @change="changcheckMangUnit" v-model="isMangUnit">多单位</el-checkbox>
                                </el-col>
              </el-row>
                              </el-form-item>
                            </el-col>
            </el-row>
            <el-row>
            <el-col :span="6">
              <el-form-item label="型号" prop="model">
                <el-input v-model="form.model" placeholder="请输入型号" />
              </el-form-item>
            </el-col>
              <el-col :span="6">
                <el-form-item label="颜色" prop="color">
                  <el-input v-model="form.color" placeholder="请输入颜色" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="基础重量(kg)" prop="weight">
                  <el-input v-model="form.weight" placeholder="请输入基础重量(kg)" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="保质期天数" prop="expiryNum">
                  <el-input v-model="form.expiryNum" placeholder="请输入保质期天数" />
                </el-form-item>
              </el-col>

            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="类别" prop="categoryId">
                <!--  <el-input v-model="form.categoryId" placeholder="请输入产品类型" /> -->
                <treeselect v-model="form.categoryId" :options="materialcategoryOptions" :show-count="true" placeholder="请选择类别" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="序列号" prop="enableSerialNumber">
                 <!-- <el-input v-model="form.enableSerialNumber" placeholder="有无序列号" /> -->
                  <el-select v-model="form.enableSerialNumber" placeholder="有无序列号" clearable size="small">
                    <el-option
                      v-for="dict in dict.type.isSerialNumber"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="批号" prop="enableBatchNumber">
                  <!-- <el-input v-model="form.enableBatchNumber" placeholder="请输入是否开启批号" /> -->
                  <el-select v-model="form.enableBatchNumber" placeholder="有批号" clearable size="small">
                    <el-option
                      v-for="dict in dict.type.isBatchNumber"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="多属性" prop="expiryNum">
                  <el-switch v-model="switchExpiryNum">
                  </el-switch>
                </el-form-item>
              </el-col>

            </el-row>
            <br />
            <el-card class="box-card" v-if="switchExpiryNum">
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item :label="addViewValueMap.attribute.manyColor.attributeName">
                    <!-- <el-input  :placeholder="addViewValueMap.attribute.manyColor.attributeName" /> -->
                    <el-select v-model="manyColorvalue" multiple
                      :placeholder="addViewValueMap.attribute.manyColor.attributeName">
                      <el-option v-for="item in addViewValueMap.attribute.manyColor.vauleList" :key="item" :label="item"
                        :value="item">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item :label="addViewValueMap.attribute.manySize.attributeName">
                    <el-select v-model="manySizevalue" multiple
                      :placeholder="addViewValueMap.attribute.manySize.attributeName">
                      <el-option v-for="item in addViewValueMap.attribute.manySize.vauleList" :key="item" :label="item"
                        :value="item">
                      </el-option>
                    </el-select>
                    <!-- <el-input  :placeholder="addViewValueMap.attribute.manySize.attributeName" /> -->
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item :label="addViewValueMap.attribute.other1.attributeName">
                    <el-select v-model="manyOther1value" multiple
                      :placeholder="addViewValueMap.attribute.other1.attributeName">
                      <el-option v-for="item in addViewValueMap.attribute.other1.vauleList" :key="item" :label="item"
                        :value="item">
                      </el-option>
                    </el-select>
                    <!-- <el-input  :placeholder="addViewValueMap.attribute.other1.attributeName" /> -->
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item :label="addViewValueMap.attribute.other2.attributeName">
                    <el-select v-model="manyOther2value" multiple
                      :placeholder="addViewValueMap.attribute.other2.attributeName">
                      <el-option v-for="item in addViewValueMap.attribute.other2.vauleList" :key="item" :label="item"
                        :value="item">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item :label="addViewValueMap.attribute.other3.attributeName">
                    <el-select v-model="manyOther3value" multiple
                      :placeholder="addViewValueMap.attribute.other3.attributeName">
                      <el-option v-for="item in addViewValueMap.attribute.other3.vauleList" :key="item" :label="item"
                        :value="item">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="生成条码">
                    <el-switch @change="doCreateBarCode" v-model="isCreateBarCode">
                    </el-switch>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
            <el-divider content-position="center">产品价格扩展信息</el-divider>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddZnMaterialExtend" >添加
                </el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteZnMaterialExtend">删除
                </el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="infor" size="mini" @click="doplJiaGe(1,'采购价-批量设置')">采购价-批量</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="infor" size="mini" @click="doplJiaGe(2,'零售价-批量设置')">零售价-批量</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="infor" size="mini" @click="doplJiaGe(3,'销售价-批量设置')">销售价-批量</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="infor" size="mini" @click="doplJiaGe(4,'最低售价-批量设置')">最低售价-批量</el-button>
              </el-col>
            </el-row>
            <el-table :data="znMaterialExtendList" :row-class-name="rowZnMaterialExtendIndex"
              @selection-change="handleZnMaterialExtendSelectionChange" ref="znMaterialExtend">
              <el-table-column type="selection" width="50" align="center" />
              <el-table-column label="序号" align="center" prop="index" width="50" />
              <el-table-column label="条码" prop="barCode">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.barCode" type="number" @change="changeBarCode" placeholder="请输入商品条码" />
                </template>
              </el-table-column>
              <el-table-column label="单位" prop="commodityUnit">
                <template slot-scope="scope">
                  <!-- <el-form-item   label-width="0" :prop="'tableData.' + scope.$index + '.commodityUnit'" :rules="rules.commodityUnit"> -->
                      <el-input v-model="scope.row.commodityUnit" placeholder="请输入商品单位" @change="rowUnitchange(scope.row,scope.$index)" readonly/>
                  <!-- </el-form-item> -->
                </template>
              </el-table-column>
              <el-table-column label="多属性" prop="sku" v-if="switchExpiryNum">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.sku" readonly="true" placeholder="请输入多属性" />
                </template>
              </el-table-column>
              <el-table-column label="采购价" prop="purchaseDecimal">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.purchaseDecimal" placeholder="请输入采购价格" />
                </template>
              </el-table-column>
              <el-table-column label="零售价" prop="commodityDecimal">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.commodityDecimal" placeholder="请输入零售价格" />
                </template>
              </el-table-column>
              <el-table-column label="销售价" prop="wholesaleDecimal">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.wholesaleDecimal" placeholder="请输入销售价格" />
                </template>
              </el-table-column>
              <el-table-column label="最低售价" prop="lowDecimal">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.lowDecimal" placeholder="请输入最低售价" />
                </template>
              </el-table-column>

            </el-table>
            <br />
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-tab-pane>
          <el-tab-pane label="扩展信息" name="second">
             <el-form-item :label="mpShort.mfrs.name" prop="mfrs" v-if="mpShort.mfrs.enabled" >
                     <el-input v-model="form.mfrs" :placeholder="mpShort.mfrs.name" />
                   </el-form-item>
                   <el-form-item v-if="mpShort.otherField1.enabled" :label="mpShort.otherField1.name" prop="otherField1">
                     <el-input v-model="form.otherField1" :placeholder="mpShort.otherField1.name" />
                   </el-form-item>
                   <el-form-item v-if="mpShort.otherField2.enabled"  :label="mpShort.otherField2.name" prop="otherField2">
                     <el-input v-model="form.otherField2" :placeholder="mpShort.otherField2.name" />
                   </el-form-item>
                   <el-form-item v-if="mpShort.otherField3.enabled" :label="mpShort.otherField3.name" prop="otherField3">
                     <el-input v-model="form.otherField3" :placeholder="mpShort.otherField3.name" />
                   </el-form-item>
          </el-tab-pane>
          <el-tab-pane label="库存数量" name="third">
            <el-button  @click="doplStockShuliang(1,'期初库存-批量')">期初库存-批量</el-button>
            <el-button  @click="doplStockShuliang(2,'最低安全库存-批量')">最低安全库存-批量</el-button>
            <el-button  @click="doplStockShuliang(3,'最高安全库存-批量')">最高安全库存-批量</el-button>
            <br /><br />
            <el-card class="box-card">
              <el-row :gutter="20">
                <el-col :span="1">#</el-col>
                <el-col :span="4">仓库</el-col>
                <el-col :span="4">期初库存数量</el-col>
                <el-col :span="4">期初价格</el-col>
                <el-col :span="4">最低安全库存数量</el-col>
                <el-col :span="4">最高安全库存数量</el-col>
                <el-col :span="4"></el-col>
              </el-row>
              <el-divider></el-divider>
              <div v-for="(item,index) in znMaterialInitialStock" :key="(item.depotName+index)">
              <el-row :gutter="20" >
                <el-col :span="1">1</el-col>
                <el-col :span="4">
                  <el-input placeholder="请输入内容" v-model="item.depotName" readonly="readonly"></el-input>
                </el-col>
                <el-col :span="4">
                  <el-input placeholder="请输入期初数量"  v-model="item.number"></el-input>
                </el-col>
                <el-col :span="4">
                  <el-input placeholder="请输入期初价格" v-bind:readonly="item.isProfit==1"  v-model="item.price"></el-input>
                </el-col>
                <el-col :span="4">
                  <el-input placeholder="请输入最低安全数量"  v-model="item.lowSafeStock"></el-input>
                </el-col>
                <el-col :span="4">
                  <el-input placeholder="请输入最高安全数量"  v-model="item.highSafeStock"></el-input>
                </el-col>
                <el-col :span="8"></el-col>
              </el-row>
              <br/>
                </div>
            </el-card>
          </el-tab-pane>
          <el-tab-pane label="图片信息" name="fourth">
            <el-form-item label="图片名称">
              <imageUpload v-model="form.imgName" />
            </el-form-item>
          </el-tab-pane>
        </el-tabs>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="plTitle" :visible.sync="plTitledialogTableVisible" width="300px">
      <el-input v-model="plJiaGe" type="number" placeholder="请输入价格"></el-input>
       <div slot="footer" class="dialog-footer">
          <el-button @click="plTitledialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="checkPlJiaGe">确 定</el-button>
        </div>
    </el-dialog>
    <el-dialog :title="plStockTitle" :visible.sync="plStockTitledialogTableVisible" width="300px">
      <el-input v-model="plStockShuLiang" type="number" placeholder="请输入数量"></el-input>
       <div slot="footer" class="dialog-footer">
          <el-button @click="plStockTitledialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="checkPlStockShuliang">确 定</el-button>
        </div>
    </el-dialog>

        </el-dialog>
    <!-- 商品信息导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body :close-on-click-modal="false">
       <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag

      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <!-- <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据 -->
          <el-link type="info" style="font-size:12px" @click="exportTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅支持导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="upload.isUploading" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listMeteralInitialStock,
    handleEnableMaterial,
    goaddViewValueMap,
    listMaterial,
    getMaterial,
    delMaterial,
    addMaterial,
    updateMaterial,
    getMaxBarCode,
    checkMaterNameIsEx
  } from "@/api/material/material";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import { listAllDepot } from "@/api/basicsystem/depot";
  import { listAllUnit } from "@/api/material/materialunit";
 import { materialcategorytreeselect } from "@/api/material/materialcategory";
 import { listMaterialpropertyAll } from "@/api/system/materialproperty";
 import { getToken } from "@/utils/auth";
  let that;
  export default {
    name: "Material",
    dicts: ['isSerialNumber','isBatchNumber'],
    components: { Treeselect },
    data() {
      return {
           mpShort: {
                mfrs: {},
                otherField1: {},
                otherField2: {},
                otherField3: {}
              },
        isMangUnit:false,//是否多单位
        plStockTitle:null,
        plStockTitledialogTableVisible:false,
        plStockShuLiang:null,
        plStockType:null,
        plType:null,
        plJiaGe:null,
          plTitle:null,
        plTitledialogTableVisible:false,//批量修改价格
        manyColorvalue: null, //多颜色
        manySizevalue: null, //多尺寸
        manyOther1value: null, //自定义1
        manyOther2value: null, //自定义2
        manyOther3value: null, //自定义3
        isCreateBarCode: false, //是否生成条码
        /* switchExpiryNumShow:false,// */
        switchExpiryNum: false, //多属性开关
        maxBarCodeInfoChushihua:1000,//最大条码起始值
        maxBarCodeInfo: 1000, //最大条码
        activeName: 'first',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 子表选中数据
        checkedZnMaterialExtend: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 产品表格数据
        materialList: [],
        // 产品价格扩展表格数据
        znMaterialExtendList: [],
        znMaterialInitialStock:[],
        materialcategoryOptions:[],//类型树
        allUnitList:[],//计量单位
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          categoryId: null,
          name: null,
          mfrs: null,
          model: null,
          standard: null,
          color: null,
          unit: null,
          imgName: null,
          unitId: null,
          expiryNum: null,
          weight: null,
          enabled: null,
          otherField1: null,
          otherField2: null,
          otherField3: null,
          enableSerialNumber: null,
          enableBatchNumber: null,
          tenantId: null,
          deleteFlag: null
        },
        // 导入(新增)参数
        upload: {
          //0 新增，1删除
          type:0,
          // 是否显示弹出层（人员导入）
          open: false,
          // 弹出层标题（人员导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/material/material/importData",
          // 上传的地址
          deleteUrl: process.env.VUE_APP_BASE_API + "/material/material/importDelete"
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: { name: [
          { required: true, message: "名称不能为空", trigger: "blur" },

        ],
        },
        addViewValueMap: null //进入页面前获取的数据
      };
    },
    created() {
      that = this;
      this.listAllUnit();
       this.materialcategorytreeselect();
      this.getList();

    },
    methods: {
      getUnitName(row, column){
        if(row.unitId !=null){
          // console.log(this.allUnitList)
          let units = this.allUnitList.find(item => item.id == row.unitId);
           return units !=undefined ?units.name:row.unit(row.unitId+"找不到对应单位");
        }else{
          return row.unit;
        }
      },
      rowUnitchange(row,index){
        // if(this.znMaterialExtendList.length>0){
        //   this.znMaterialExtendList.forEach(function(item){
        //      item.
        //   })
        // }
      },
       /** 导入按钮操作 */
      handleImport() {
        this.upload.title = "商品导入";
        this.upload.open = true;
      },
      /** 下载模板操作 */
      exportTemplate() {
            this.download('material/material/exportTemplate', {
              ...this.queryParams
            }, `商品导入模板_${new Date().getTime()}.xlsx`)
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
           this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
           this.upload.open = false;
           this.upload.isUploading = false;
           this.$refs.upload.clearFiles();
           this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
           this.getList();
      },
      // 提交上传文件
      submitFileForm() {
          this.$refs.upload.submit();
      },
      checkName(){

checkMaterNameIsEx(this.form).then(response => {
        let object= response.data;
        // console.log(object)
        if(parseInt(object.isName)==0){
          this.form.chineseChar=object.chineseChar;
        }else{
          this.$modal.msgError("商品名称重复");
          return;
        }

        });

      },
       loadParseMaterialProperty(mpList) {
           // let mpList = Vue.ls.get('materialPropertyList')
            for (let i = 0; i < mpList.length; i++) {
              if (mpList[i].nativeName === "制造商") {
                this.mpShort.mfrs.name = mpList[i].anotherName
                this.mpShort.mfrs.enabled = mpList[i].enabled
              }
              if (mpList[i].nativeName === "自定义1") {
                this.mpShort.otherField1.name = mpList[i].anotherName
                this.mpShort.otherField1.enabled = mpList[i].enabled
              }
              if (mpList[i].nativeName === "自定义2") {
                this.mpShort.otherField2.name = mpList[i].anotherName
                this.mpShort.otherField2.enabled = mpList[i].enabled
              }
              if (mpList[i].nativeName === "自定义3") {
                this.mpShort.otherField3.name = mpList[i].anotherName
                this.mpShort.otherField3.enabled = mpList[i].enabled
              }
            }
          },
       /** 查询产品属性所有列表 */
          getMaterialPropertyAllList() {
            listMaterialpropertyAll(this.queryParams).then(response => {
            let mpList = response.data;
              that.loadParseMaterialProperty(mpList);
            });
          },
      /** 设置启用禁用按钮操作 */
      handleEnable(msg,enable) {
        const ids =  this.ids;
        this.$modal.confirm('是否确认'+msg+'产品编号为"' + ids + '"的数据项？').then(function() {
          return handleEnableMaterial(ids,enable);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess(msg+"成功");
        }).catch(() => {});
      },
       handlePlCommand(command) {//批量操作
              if( this.ids==null|| this.ids==""){
                this.$modal.msgError("请勾选要操作的商品");
                return;
              }
             // this.$message('click on item ' + this.ids);
              if(command==1){//启用
              this.handleEnable("启用","1");
              }else if(command==2){//禁用
this.handleEnable("禁用用","0");
              }else if(command==3){//修正库存
                 this.$modal.msgError("待开发");
              }
            },
      /** 查询类型下拉树结构 */
      materialcategorytreeselect() {
        materialcategorytreeselect().then(response => {
          this.materialcategoryOptions = response.data;
          // console.log( this.materialcategoryOptions)
        });
      },
      /** 查询产品列表 */
      getList() {
        this.loading = true;
        listMaterial(this.queryParams).then(response => {
          this.materialList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },listAllUnit(){
        listAllUnit(this.queryParams).then(response => {
          this.allUnitList = response.data;
        });
      },
      /** 查询所产仓库 */
      listAllDepot() {//废弃 使用listMeteralInitialStock
        this.loading = true;
        that.znMaterialInitialStock=[];
        listAllDepot(this.queryParams).then(response => {
         /* this.materialList = response.rows;
          this.total = response.total;
          this.loading = false; */
          // console.log(response.list)
          let depotAll=response.list;
          depotAll.forEach(function(item, index) {
                         //item2 就是当日按循环到的对象
                         //index2是循环的索引，从0开始
           let obj = {};
           obj.depotId = item.id;
           obj.name = item.name;
           obj.number = 0;
           obj.lowSafeStock = "";
           obj.highSafeStock = "";
           that.znMaterialInitialStock.push(obj);
             })
        });
      },listMeteralInitialStock(id){//查询期初库存
 that.znMaterialInitialStock=[];
 let queryStock={id:id};
        listMeteralInitialStock(queryStock).then(response => {
          that.znMaterialInitialStock=response.data;
         /* this.materialList = response.rows;
          this.total = response.total;
          this.loading = false; */
             })
      },
      /** 进入页面前获取的数据 */
      goaddViewValueMap() {
        this.loading = true;
        goaddViewValueMap(this.queryParams).then(response => {
          this.addViewValueMap = response.data;
          console.log(this.addViewValueMap)
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          categoryId: null,
          name: null,
          mfrs: null,
          model: null,
          standard: null,
          color: null,
          unit: null,
          remark: null,
          imgName: null,
          unitId: null,
          expiryNum: null,
          weight: null,
          enabled: null,
          otherField1: null,
          otherField2: null,
          otherField3: null,
          enableSerialNumber: null,
          enableBatchNumber: null,
          tenantId: null,
          deleteFlag: null,
          chineseChar:null
        };
        this.znMaterialExtendList = [];
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.maxBarCodeAction(0);
        this.goaddViewValueMap();
        this.listMeteralInitialStock();
        this.getMaterialPropertyAllList();
        this.reset();
        this.open = true;
        this.title = "添加产品";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.maxBarCodeAction(1);
        this.goaddViewValueMap();
        this.listMeteralInitialStock(row.id);
        this.listAllUnit();
        this.getMaterialPropertyAllList();
        this.reset();
        const id = row.id || this.ids
        getMaterial(id).then(response => {
          this.form = response.data;
          this.znMaterialExtendList = response.data.znMaterialExtendList;
          this.open = true;
          this.title = "修改产品";
          this.isMangUnit = this.form.unitId !=null
        });
      },
      /** 提交按钮 */
      submitForm() {
        if(!this.isMangUnit){
          if(this.form.unit==null||this.form.unit==""){
             this.$modal.msgError("单位必须填写");
            return;
          }
        }
        this.$refs["form"].validate(valid => {
          if (valid) {
            if(!this.changeBarCode()){
              return;
            }
            if(this.znMaterialExtendList==null||this.znMaterialExtendList.length==0){
               this.$modal.msgError("最少填一条条码");
               return;
            }
            if(this.isMangUnit){
              if(this.znMaterialExtendList.length<2){
                this.$modal.msgError("多单位的商品条码行数至少要有两行，请再新增一行条码信息！");
                 return;
              }
            }else{//单个单位 ，判断单位是否有乱填
            let unit = this.form.unit;
            // let flag = this.znMaterialExtendList.findIndex(item=>item.commodityUnit !== unit)
             let newArray = this.znMaterialExtendList.filter(item =>{
                return item.commodityUnit !== unit;
             });

              if(newArray.length>0){
                // let commodityUnit = newArray[0].commodityUnit;
                let msg ="";
                let that = this;
                newArray.forEach(function(item, index) {
                  //item 就是当日按循环到的对象
                  //index是循环的索引，从0开始
                  msg += "单位【"+item.commodityUnit+"】请修改为【"+that.form.unit+"】；";
                });
                if(msg.endsWith("；")){
                 msg = msg.substring(0,msg.lastIndexOf("；")) +"。";
                }
                // this.$modal.msgError("条码之后的单位填写有误，单位【"+commodityUnit+"】请修改为"+this.form.unit);
                this.$modal.msgError("条码之后的单位填写有误。"+msg);
                return;
              }
            }
            this.form.znMaterialExtendList = this.znMaterialExtendList;
            this.form.znMaterialInitialStocks=this.znMaterialInitialStock;
            if (this.form.id != null) {
              updateMaterial(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addMaterial(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        // console.log("aa")
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除产品编号为"' + ids + '"的数据项？').then(function() {
          return delMaterial(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 产品价格扩展序号 */
      rowZnMaterialExtendIndex({
        row,
        rowIndex
      }) {
        row.index = rowIndex + 1;
      },
      /** 产品价格扩展添加按钮操作 */
      handleAddZnMaterialExtend() {
        let obj = {};
        let _that = this;
        obj.barCode = this.maxBarCodeInfo + "";
        if(this.form.unitId ==null){
           obj.commodityUnit = this.form.unit;
        }else{
          let unit = null;
          this.allUnitList.forEach(function(item, index) {
                if(item.id==_that.form.unitId){
                    unit = item;
                }
          });
          let len = this.znMaterialExtendList.length;
          if(len ==0){
             obj.commodityUnit = this.form.unit;
          }else if(len ==1){
             obj.commodityUnit = unit.otherUnit;
          }else if(len ==2){
            if(unit.otherUnitTwo !=null && unit.otherUnitTwo !=""){
              obj.commodityUnit = unit.otherUnitTwo;
            }else{
              obj.commodityUnit = unit.otherUnit;
            }
          }else{
            if(unit.otherUnitThree !=null && unit.otherUnitThree !=""){
              obj.commodityUnit = unit.otherUnitThree;
            }else if(unit.otherUnitTwo !=null && unit.otherUnitTwo !=""){
              obj.commodityUnit = unit.otherUnitTwo;
            }else{
              obj.commodityUnit = unit.otherUnit;
            }
          }
        }
        obj.sku = "";
        obj.purchaseDecimal = "";
        obj.commodityDecimal = "";
        obj.wholesaleDecimal = "";
        obj.lowDecimal = "";
        obj.defaultFlag = "";
        obj.createSerial = "";
        obj.updateSerial = "";
        obj.tenantId = "";
        obj.deleteFlag = "";
        this.znMaterialExtendList.push(obj);
        this.maxBarCodeInfo = this.maxBarCodeInfo + 1;
      },
      /** 产品价格扩展删除按钮操作 */
      handleDeleteZnMaterialExtend() {
        if (this.checkedZnMaterialExtend.length == 0) {
          this.$modal.msgError("请先选择要删除的产品价格扩展数据");
        } else {
          const znMaterialExtendList = this.znMaterialExtendList;
          const checkedZnMaterialExtend = this.checkedZnMaterialExtend;
          this.znMaterialExtendList = znMaterialExtendList.filter(function(item) {
            return checkedZnMaterialExtend.indexOf(item.index) == -1
          });
        }
      },
      /** 复选框选中数据 */
      handleZnMaterialExtendSelectionChange(selection) {
        this.checkedZnMaterialExtend = selection.map(item => item.index)
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('material/material/export', {
          ...this.queryParams
        }, `material_${new Date().getTime()}.xlsx`)
      },
      maxBarCodeAction(type) { //获取最大条形码 type 0 新增 添加空行，1编辑 不添加空行
        getMaxBarCode({}).then(response => {
          this.maxBarCodeInfoChushihua = response.data.barCode - 0 + 1;
          this.maxBarCodeInfo = response.data.barCode - 0 + 1;
          if(type ==0){
           let obj = {};
           obj.barCode = this.maxBarCodeInfo  + "";
           obj.commodityUnit = "";
           obj.sku = "";
           obj.purchaseDecimal = "";
           obj.commodityDecimal = "";
           obj.wholesaleDecimal = "";
           obj.lowDecimal = "";
           obj.defaultFlag = "";
           obj.createSerial = "";
           obj.updateSerial = "";
           obj.tenantId = "";
           obj.deleteFlag = "";
           this.znMaterialExtendList.push(obj);
           this.maxBarCodeInfo = this.maxBarCodeInfo + 1;
          }
          this.loading = false;
        });
        /* getMaxBarCode({}).then((res)=> {
           if (res && res.code === 200) {
             this.maxBarCodeInfo = res.data.barCode - 0
           }
         }) */
      },
      changcheckMangUnit(value){//多选框被选
        if(value){
          if(this.switchExpiryNum){
            this.isMangUnit=false;
             this.$modal.msgError("请先取消多属性，在进行勾选多单位");
            return;
          }
          this.mangUnitChange(this.form.unitId)
        }else{
          let basicUnit = that.form.unit;
          this.znMaterialExtendList.forEach(function(item, index) {
            if(index ==0){
              basicUnit =  item.commodityUnit
            }else{
               item.commodityUnit = basicUnit;
            }
          });
        }
      },
      unitChange(value) {//单个单位改变
        // console.log(value);
        this.znMaterialExtendList.forEach(function(item, index) {
          item.commodityUnit = that.form.unit;
        })
      },
      mangUnitChange(value){//多单位改变
      // console.log(value)
      let itemUnit=null;
    this.allUnitList.forEach(function(item, index) {
          //item 就是当日按循环到的对象
          //index是循环的索引，从0开始
          if(item.id==value){
            itemUnit=item;
          }
        })
        if(this.switchExpiryNum){
          this.isMangUnit=false;
           this.$modal.msgError("请先取消多属性，在进行勾选多单位");
          return;
        }
       this.form.unit = itemUnit.basicUnit;
         let obj = {};
        // that.znMaterialExtendList=[];
        if(that.znMaterialExtendList.length==0){
          obj.barCode = that.maxBarCodeInfoChushihua +1+ "";
          obj.commodityUnit =itemUnit.basicUnit;
          obj.sku = "";
          obj.purchaseDecimal = "";
          obj.commodityDecimal = "";
          obj.wholesaleDecimal = "";
          obj.lowDecimal = "";
          obj.defaultFlag = "";
          obj.createSerial = "";
          obj.updateSerial = "";
          obj.tenantId = "";
          obj.deleteFlag = "";
          that.znMaterialExtendList.push(obj);

          if(itemUnit.otherUnit!=null&&itemUnit.otherUnit!=""){
            obj = {};
            obj.barCode = that.maxBarCodeInfoChushihua +2+ "";
            obj.commodityUnit =itemUnit.otherUnit;
            obj.sku = "";
            obj.purchaseDecimal = "";
            obj.commodityDecimal = "";
            obj.wholesaleDecimal = "";
            obj.lowDecimal = "";
            obj.defaultFlag = "";
            obj.createSerial = "";
            obj.updateSerial = "";
            obj.tenantId = "";
            obj.deleteFlag = "";
            that.znMaterialExtendList.push(obj);
          }

          if(itemUnit.otherUnitTwo!=null&&itemUnit.otherUnitTwo!=""){
            obj = {};
            obj.barCode = that.maxBarCodeInfoChushihua +3+ "";
            obj.commodityUnit =itemUnit.otherUnitTwo;
            obj.sku = "";
            obj.purchaseDecimal = "";
            obj.commodityDecimal = "";
            obj.wholesaleDecimal = "";
            obj.lowDecimal = "";
            obj.defaultFlag = "";
            obj.createSerial = "";
            obj.updateSerial = "";
            obj.tenantId = "";
            obj.deleteFlag = "";
            that.znMaterialExtendList.push(obj);
          }

          if(itemUnit.otherUnitThree!=null&&itemUnit.otherUnitThree!=""){
            obj = {};
            obj.barCode = that.maxBarCodeInfoChushihua +4+ "";
            obj.commodityUnit =itemUnit.otherUnitThree;
            obj.sku = "";
            obj.purchaseDecimal = "";
            obj.commodityDecimal = "";
            obj.wholesaleDecimal = "";
            obj.lowDecimal = "";
            obj.defaultFlag = "";
            obj.createSerial = "";
            obj.updateSerial = "";
            obj.tenantId = "";
            obj.deleteFlag = "";
            that.znMaterialExtendList.push(obj);
          }
        }else{
           let len = this.znMaterialExtendList.length;
           this.znMaterialExtendList.forEach((item,index,arr) =>{
              if(index ==0){
                item.commodityUnit =itemUnit.basicUnit;
              }else {
                 if(len ==2){
                      item.commodityUnit =itemUnit.otherUnit;
                 }else if(len >=3){
                   if(index ==1){
                      item.commodityUnit =itemUnit.otherUnit;
                   }else if(index ==2){
                     if(itemUnit.otherUnitTwo!=null&&itemUnit.otherUnitTwo!=""){
                        item.commodityUnit =itemUnit.otherUnitTwo;
                     }else{
                        item.commodityUnit =itemUnit.otherUnit;
                     }
                   }else if(index >=3){
                     if(itemUnit.otherUnitThree!=null&&itemUnit.otherUnitThree!=""){
                        item.commodityUnit =itemUnit.otherUnitThree;
                     }else if(itemUnit.otherUnitTwo!=null&&itemUnit.otherUnitTwo!=""){
                        item.commodityUnit =itemUnit.otherUnitTwo;
                     }else{
                        item.commodityUnit =itemUnit.otherUnit;
                     }
                   }
                 }
              }
           });
           if(len ==1){
             if(itemUnit.otherUnit!=null&&itemUnit.otherUnit!=""){
               obj = {};
               obj.barCode = that.maxBarCodeInfoChushihua +2+ "";
               obj.commodityUnit =itemUnit.otherUnit;
               obj.sku = "";
               obj.purchaseDecimal = "";
               obj.commodityDecimal = "";
               obj.wholesaleDecimal = "";
               obj.lowDecimal = "";
               obj.defaultFlag = "";
               obj.createSerial = "";
               obj.updateSerial = "";
               obj.tenantId = "";
               obj.deleteFlag = "";
               that.znMaterialExtendList.push(obj);
             }
           }
        }

      },changeBarCode(value){//条码改变 进行重复性判断
let f=true;
/*      let bflag=false; */
  this.znMaterialExtendList.forEach(function(item, index) {
                 //item2 就是当日按循环到的对象
                 //index2是循环的索引，从0开始
                 if(item.barCode==null||item.barCode==""){
                   if(f){
                       that.$modal.msgError("第"+(index+1)+"条，条码："+item.barCode+" 为空");
                   }

                    //bflag=true;
                  // throw Error();
                  f=false;
                 }
           that.znMaterialExtendList.forEach(function(item2, index2) {
                          //item2 就是当日按循环到的对象
                          //index2是循环的索引，从0开始

                    if(item.barCode==item2.barCode&&index!=index2){
                      if(f){
                      that.$modal.msgError("第"+(index2+1)+"条，条码："+item2.barCode+" 重复");
                      }
                      //bflag=true;
                    // throw Error();
                    f=false;
                    }

              })

     })
return f;

      },doplJiaGe(type,title){//批量设置价格
      this.plType=type;
      this.plTitle=title;
      this.plJiaGe=null;
      this.plTitledialogTableVisible=true;

      },checkPlJiaGe(){
  this.znMaterialExtendList.forEach(function(item, index) {
                 //item2 就是当日按循环到的对象
                 //index2是循环的索引，从0开始
        if(that.plType==1){
         item.purchaseDecimal = that.plJiaGe;
        }else if(that.plType==2){
 item.commodityDecimal = that.plJiaGe;
        }if(that.plType==3){
 item.wholesaleDecimal = that.plJiaGe;
        }if(that.plType==4){
 item.lowDecimal = that.plJiaGe;
        }
     })
     this.plTitledialogTableVisible=false;
      },doplStockShuliang(type,title){//批量设置数量
      this.plStockType=type;
      this.plStockTitle=title;
      this.plStockShuLiang=null;
      this.plStockTitledialogTableVisible=true;

      },checkPlStockShuliang(){
  this.znMaterialInitialStock.forEach(function(item, index) {
                 //item2 就是当日按循环到的对象
                 //index2是循环的索引，从0开始
        if(that.plStockType==1){
         item.number = that.plStockShuLiang;
        }else if(that.plStockType==2){
 item.lowSafeStock = that.plStockShuLiang;
        }else if(that.plStockType==3){
 item.highSafeStock = that.plStockShuLiang;
        }
     })
      this.plStockTitledialogTableVisible=false;
      },
      handleTabClick(tab, event) {
        // console.log(tab, event);
      },
      doCreateBarCode() { //生成条码
        if(this.isMangUnit){
          this.$modal.msgError("请取消多单位，在进行条码生成");
           this.isCreateBarCode=false;
          return;
        }
        if(this.form.unit==null||this.form.unit==""){
          this.isCreateBarCode=false;
           this.$modal.msgError("请先填写单位");
          return;
        }
        if (this.isCreateBarCode) {
          let count=0;
          let mang=[];
          let mangOne=null;
          let mangTwo=null;
          if(this.manyColorvalue!=null&&this.manyColorvalue!=""){
            count=count+1;
            mangOne=this.manyColorvalue;
          }
          if(this.manySizevalue!=null&&this.manySizevalue!=""){
            count=count+1;
            if(mangOne!=null){
              mangTwo=this.manySizevalue;
            }
          }
          if(this.manyOther1value!=null&&this.manyOther1value!=""){
            count=count+1;
            if(mangOne!=null){
              mangTwo=this.manyOther1value;
            }
          }
          if(this.manyOther2value!=null&&this.manyOther2value!=""){
            count=count+1;
            if(mangOne!=null){
              mangTwo=this.manyOther2value;
            }
          }
          if(this.manyOther3value!=null&&this.manyOther3value!=""){
            count=count+1;
            if(mangOne!=null){
              mangTwo=this.manyOther3value;
            }
          }
          if(count!=2){
             this.isCreateBarCode=false;
             this.$modal.msgError("请选择两个属性");
             return;
          }
          // console.log(this.manyColorvalue)
          mangOne.forEach(function(item, index) {
                      //item 就是当日按循环到的对象
                      //index是循环的索引，从0开始
               mangTwo.forEach(function(item2, index2) {
                           //item2 就是当日按循环到的对象
                           //index2是循环的索引，从0开始
                        mang.push(item+","+item2);
               })
          })
           this.znMaterialExtendList=[];
          mang.forEach(function(item, index) {
                      //item2 就是当日按循环到的对象
                      //index2是循环的索引，从0开始
                      let obj = {};
                      obj.barCode = that.maxBarCodeInfoChushihua +index+ "";
                      obj.commodityUnit =that.form.unit;
                      obj.sku = item;
                      obj.purchaseDecimal = "";
                      obj.commodityDecimal = "";
                      obj.wholesaleDecimal = "";
                      obj.lowDecimal = "";
                      obj.defaultFlag = "";
                      obj.createSerial = "";
                      obj.updateSerial = "";
                      obj.tenantId = "";
                      obj.deleteFlag = "";
                      that.znMaterialExtendList.push(obj);

          })
          // console.log(mang)
        }else{
          //取消还原初始
          this.znMaterialExtendList=[];
          this.maxBarCodeInfo =  this.maxBarCodeInfoChushihua;
          let obj = {};
          obj.barCode = this.maxBarCodeInfo + "";
          obj.commodityUnit = "";
          obj.sku = "";
          obj.purchaseDecimal = "";
          obj.commodityDecimal = "";
          obj.wholesaleDecimal = "";
          obj.lowDecimal = "";
          obj.defaultFlag = "";
          obj.createSerial = "";
          obj.updateSerial = "";
          obj.tenantId = "";
          obj.deleteFlag = "";
          this.znMaterialExtendList.push(obj);
          this.maxBarCodeInfo = this.maxBarCodeInfo + 1;
        }
      }
    }
  };
</script>
